<template>
    <div>
        <el-form :model="form">
            <el-form-item label="姓名">
                <el-input v-model="form.name" />
            </el-form-item>
            <el-form-item label="年龄">
                <el-input v-model="form.age" type="number" />
            </el-form-item>
            <el-form-item label="性别">
                <el-select v-model="form.sex" placeholder="请选择性别">
                    <el-option v-for="item in sexList" :label="item.label" :value="item.value" />
                </el-select>
            </el-form-item>
            <el-form-item label="语文">
                <el-input v-model.number="form.score.yw" type="number" />
            </el-form-item>
            <el-form-item label="数学">
                <el-input v-model.number="form.score.sx" type="number" />
            </el-form-item>
            <el-form-item label="英语">
                <el-input v-model.number="form.score.yy" type="number" />
            </el-form-item>
            <el-form-item>
                <el-button @click="form = null">重置</el-button>
                <el-button type="primary" @click="submit">提交</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
import {ref} from 'vue'
export default {
    name: 'Report',
    emit: ['addStu'],
    setup(props, ctx) {
        const sexList = [{ label: '男', value: '女', }, { label: '女', value: '女', },];
        const form = ref({ name: '', age: 0, sex: '', score: { yw: 0, sx: 0, yy: 0 }, avatar: require('@/assets/img/avatar' + Math.floor(Math.random() * 10) + '.png'), });
        const submit = function () {
            ctx.emit('addStu', form.value);
            form.value = { name: '', age: 0, sex: '', score: { yw: 0, sx: 0, yy: 0 }, avatar: require('@/assets/img/avatar' + Math.floor(Math.random() * 10) + '.png'), };
        }
        return {
            form,
            sexList,
            submit
        }
    }
}
</script>

<style>
.icon {
  height: 25px;
}
</style>